package com.smart.util;

import java.util.Map;
import java.util.HashMap;
import org.apache.commons.beanutils.BeanUtils;
import java.lang.reflect.InvocationTargetException;

/**
 * @author lgb
 * @date 2020年6月11日 上午9:49:27
 * Copyright (C) 深圳工勘科技
 * @说明: map工具
 **/
public class MapTools {

	/**
	 * 将Object对象里面的属性和值转化成Map对象
	 * @param obj
	 * @return
	 * @throws IllegalAccessException
	 **/
	@SuppressWarnings("unchecked")
	public static Map<String,String> convertToMap(Object obj) {
		try {
			if (obj instanceof Map) {
				return (Map<String,String>) obj;
			}
			Map<String,String> returnMap = BeanUtils.describe(obj);
			returnMap.remove("class");
			return returnMap;
		} catch (IllegalAccessException e1) {
			e1.getMessage();
		} catch (InvocationTargetException e2) {
			e2.getMessage();
		} catch (NoSuchMethodException e3) {
			e3.getMessage();
		}
		return new HashMap<String,String>();
	}

}